﻿using System.Linq;
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.Interfaces;

namespace iss.sg4210.se18.team6s.jass.DAL.DataAccess.MSSQL
{
    public class CompanyDAO : ObjectDAO, ICompany
    {
        public CompanyDAO()
            : base() { }

        public IQueryable<Company> FindAllCompanies()
        {
            return jassEntities.Companies;
        }

        public Company GetCompany(int companyId)
        {
            return jassEntities.Companies.SingleOrDefault(c => c.Id == companyId);
        }

        public void AddCompany(Company company)
        {
            jassEntities.AddToCompanies(company);
            Save();
        }

        public void UpdateCompany(Company company)
        {
            jassEntities.Companies.ApplyCurrentValues(company);
            Save();
        }

        public void DeleteCompany(int companyId)
        {
            Company company = GetCompany(companyId); ;
            jassEntities.Companies.DeleteObject(company);
            Save();
        }
    }
}
